<template>
  <div>
    <van-nav-bar :title="key+'的搜索结果'" />
    <van-list
      v-model="
      loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell
        v-for="item in list"
        :key="item.art_id"
        :title="item.title"
        @click="$router.push({name:'article',query:{id:item.art_id}})"
      />
    </van-list>
  </div>
</template>

<script>
import { getSearchResultAPI } from '@/api'
export default {
  data() {
    return {
      name: "result",
      property: 'value',
      list: [],
      key: this.$route.query.key,
      loading: false,
      finished: false,
      page: 1 // 页数
    };
  },
  methods: {
    async onLoad() {
      const res = await getSearchResultAPI({
        page: this.page++,
        per_page: 10,
        q: this.key
      })
      this.list.push(...res.data.data.results)
      this.loading = false
      if (this.list.length >= res.data.data.total_count) {
        //   全部加载完毕
        this.finished = true;
      }
    },
  },
  created() {
    // console.log('this.$route.query.suggestList:', this.$route.query.suggestList);
    // this.suggestList = this.$route.query.suggestList
  }
}
</script>

<style>
</style>